package dolf.window;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.metal.DefaultMetalTheme;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.plaf.metal.OceanTheme;

import dolf.window.themes.AquaTheme;
import dolf.window.themes.CharcoalTheme;
import dolf.window.themes.ContrastTheme;
import dolf.window.themes.EmeraldTheme;
import dolf.window.themes.RubyTheme;

public abstract class Window extends JFrame {
	
	private static final long serialVersionUID = 1L;

	protected void initialize(String name) {
		setTitle(name);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setResizable(false);
	}
	
	public void initLookAndFeel() {
		 String lookAndFeel = ConfigurationHandler.getInstance().getProperty("lookandfeel");
	     String theme = ConfigurationHandler.getInstance().getProperty("theme");
	     
	     try {
	    	 if (lookAndFeel.equals(UIManager.getCrossPlatformLookAndFeelClassName())) {
	    		 if (theme.equals("DefaultMetal"))
	    			 MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
	    		 else if (theme.equals("Ocean"))
		             MetalLookAndFeel.setCurrentTheme(new OceanTheme());
	    		 else if (theme.equals("Aqua"))
					 MetalLookAndFeel.setCurrentTheme(new AquaTheme());
	    		 else if (theme.equals("Charcoal"))
					 MetalLookAndFeel.setCurrentTheme(new CharcoalTheme());
	    		 else if (theme.equals("Contrast"))
					 MetalLookAndFeel.setCurrentTheme(new ContrastTheme());
	    		 else if (theme.equals("Emerald"))
					 MetalLookAndFeel.setCurrentTheme(new EmeraldTheme());
	    		 else if (theme.equals("Ruby"))
					 MetalLookAndFeel.setCurrentTheme(new RubyTheme());

	    		 UIManager.setLookAndFeel(new MetalLookAndFeel()); 
	    	 } else UIManager.setLookAndFeel(lookAndFeel);
	    	 
	    	SwingUtilities.updateComponentTreeUI(this);
	    	pack();   	
	     }
	     catch (Exception e) {
	    	 System.err.println("could not use look and feel "+lookAndFeel);
	    	 e.printStackTrace();
	     }
	}
	abstract public void draw();
	
	public void actualize() {
		invalidate();
		validate();
		repaint();
	}
}
